﻿using System;
using System.Data;


public partial class manager_temt_PointTemp_Default : System.Web.UI.Page
{
    DBHelper db = new DBHelper();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindData();
        }
    }
    private void bindData()
    {
        DataTable dt = db.getList("select * from dict_point_temp");

        rptDeApply_1.DataSource = dt;
        rptDeApply_1.DataBind();

    }

    protected void btnGet_Click(object sender, EventArgs e)
    {
        string hid = hidBID.Value;
        string sql = "select* from dict_point_temp where id=" + hid;
        DataTable dt = db.getList(sql);
        if (dt.Rows.Count > 0)
        {
            DataRow dr = dt.Rows[0];
            txt_mc.Text = dr["mc"].ToString();
            txt_point.Text = dr["point"].ToString();
            string isusstr = "0";
            if (dr["isUsing"].ToString() == "True")
            {
                isusstr = "1";
            }
            ddlIsUsing.SelectedValue = isusstr;
        }
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string hid = hidBID.Value;
        string mc = "";
        string point = "";
        string isUsing = "";
        string type = "";

        string sql = "";
        if (hid == "")
        {
            mc = txt_mc.Text;
            isUsing = ddlIsUsing.SelectedValue;
            type = ddlType.SelectedValue;

            point = txt_point.Text;
            if (mc != "" && isUsing != "" && point != "")
            {
                sql = "insert into dict_point_temp(mc,isUsing,point,type)values('" + mc + "','" + isUsing + "','" + point + "','" + type + "')";
            }
            else
            {
                Response.Write(CommonHelper.alertMsg("请完善所有信息")); return;
            }
        }
        else
        {
            mc = txt_mc.Text;
            isUsing = ddlIsUsing.SelectedValue;
            point = txt_point.Text;
            if (mc != "" && isUsing != "" && point != "")
            {
                sql = "update dict_point_temp set mc='" + mc + "',isUsing='" + isUsing + "',point='" + point + "',type='" + type + "' where id=" + hid;
            }
            else
            {
                Response.Write(CommonHelper.alertMsg("请完善所有信息")); return;
            }
        }

        int i = db.executeNoneQuery(sql);
        if (i > 0)
        {
            CacheHelper.clearAllCache();
            Response.Write(CommonHelper.alertMsgAndRedirect("保存成功", Request.Url.LocalPath + Request.Url.Query));
        }
        else
        {
            Response.Write(CommonHelper.alertMsg("保存失败"));
        }
    }
}